Ext.define('Module.task.TaskDetails',{
	extend:'Ext.window.Window',
	maximized:true,
	width:1000,
	height:640,
	layout:'fit',
	border: false,
	title:'任务详情',
	iconCls:'',
	type: 1,
	rwdata: undefined,
	requires: ['Sh.ux.VideosPlayer'],
	initComponent : function() {
		var me = this;
		var d = me.rwdata;
		var workTask = [{
			fieldLabel:'变电站', 
			value:d.bdz_name
		},{
			fieldLabel:'完成阶段', 
			value:d.f_stage
		},{
			fieldLabel:'停电范围', 
			value:d.powercut
		},{
			fieldLabel:'班组', 
			value:d.bz_name
		},{
			fieldLabel:'专业', 
			value:d.bzzy_name
		},{
			fieldLabel:'编制人', 
			value:d.planuser
		},{
			fieldLabel:'编制时间', 
			value:d.plan_time
		},{
			fieldLabel:'计划开始时间', 
			value:formatDate(d.starttime),
			labelWidth: 80,
			columnWidth: 1/2
		},{
			fieldLabel:'计划结束时间', 
			value:formatDate(d.endtime),
			labelWidth: 80,
			columnWidth: 1/2
		},{
			xtype: 'textarea',
			fieldLabel:'任务内容', 
			value:d.content,
			columnWidth: 1
		}];
		var xsTask = [{
			fieldLabel:'变电站', 
			value:d.transformer
		},{
			fieldLabel:'电压等级', 
			value:d.voltage_grade
		},{
			fieldLabel:'巡视类型', 
			value:d.type
		},{
			fieldLabel:'班组', 
			value:d.bz_name
		},{
			fieldLabel:'专业', 
			value:d.bzzy_name
		},{
			fieldLabel:'巡视人员', 
			value:d.xsuser
		},{
			fieldLabel:'天气', 
			value:d.weather
		},{
			fieldLabel:'温度', 
			value:d.temperature
		},{
			fieldLabel:'巡视人员', 
			value:d.xsuser
		},{
			fieldLabel:'发现缺陷数', 
			value:d.defect_number,
			labelWidth: 70
		},{
			fieldLabel:'发现隐患数', 
			value:d.hdanger_number,
			labelWidth: 70
		},{
			fieldLabel:'巡视结果', 
			value:d.result
		},{
			fieldLabel:'巡视是否完成', 
			value:d.isfinish == 1?'是':'否',
			labelWidth: 80
		},{
			fieldLabel:'巡视未完成原因', 
			value:d.nofinish_why,
			labelWidth: 90
		},{
			fieldLabel:'是否归档', 
			value:d.file == 1?'是':'否'
		},{
			fieldLabel:'同步时间', 
			value:formatDate(d.syntime)
		},{
			fieldLabel:'巡视开始时间', 
			value:formatDate(d.starttime),
			labelWidth: 80,
			columnWidth: 1/2
		},{
			fieldLabel:'巡视结束时间', 
			value:formatDate(d.endtime),
			labelWidth: 80,
			columnWidth: 1/2
		},{
			xtype: 'textarea',
			fieldLabel:'巡视内容', 
			value:d.content,
			columnWidth: 1
		}];
		var panel = Ext.create('Ext.form.Panel',{
			layout: 'column',
			bodyPadding: 5,
			autoScroll:true,
			defaults: {
				columnWidth: 1,
				xtype: 'fieldset',
				height: '33%',
				layout: 'column'
			},
			items:[{
				xtype:'fieldset',
				layout:'column',
				title: '任务信息',
				height:me.type == 1?200:300,
				defaults: {
					xtype: 'textfield',
					labelWidth: 60,
					columnWidth: 1/4,
					padding: '0 10 10 0',
					readOnly:true
				},
				items: me.type == 1?workTask:xsTask,
			},{
				xtype:'fieldset',
				id:me.id+'-js',
		        title: '班组角色',
		        layout: 'hbox',
		        height: 65,
		        columnWidth: 1/2,
		        defaults:{xtype: 'checkbox',padding: '0 20 0 0'},
		        items: [/*
		            { boxLabel: '工作负责人', name: 'gf', inputValue: '1'},
		            { boxLabel: '专责负责人', name: 'zf', inputValue: '2', checked: true},
		            { boxLabel: '工作班成员', name: 'cy', inputValue: '3'}
		        */],
		        listeners:{
		        	afterrender:function(){
		        		Ext.Ajax.request({
		        			url:'vm/getBzRole.do',
		        			params:{
		        				bzId:d.bz_id
		        			},
		        			success:function(response){
		        				var text = Ext.decode(response.responseText); 
		        				var jsDom = Ext.getCmp(me.id+'-js');
		        				for(var i =0;i<text.length;i++){
		        					jsDom.add({
			        					 boxLabel: text[i].name,  inputValue: text[i].id
			        				});
		        				}
		        			}
		        		});
		        	}
		        }
		    },{
		    	xtype:'fieldset',
		    	layout: 'hbox',
		    	id:me.id+'-gc',
		    	columnWidth: 1/2,
				defaults:{xtype: 'checkbox',padding: '0 20 0 0'},
				height: 65,
		        title: '作业过程',
		        items: [/*
		            { boxLabel: '许可', name: 'xk', inputValue: '1' },
		            { boxLabel: '唱票', name: 'cp', inputValue: '2', checked: true },
		            { boxLabel: '工作', name: 'gz', inputValue: '3' },
		            { boxLabel: '验收结果', name: 'ys', inputValue: '4' }
		        */],
		        listeners:{
		        	afterrender:function(){
		        		Ext.Ajax.request({
		        			url:'vm/getGc.do',
		        			params:{
		        				rwid:d.id
		        			},
		        			success:function(response){
		        				var text = Ext.decode(response.responseText); 
		        				var jsDom = Ext.getCmp(me.id+'-gc');
		        				for(var i =0;i<text.length;i++){
		        					jsDom.add({
			        					 boxLabel: text[i].name,  inputValue: text[i].id
			        				});
		        				}
		        			}
		        		});
		        	}
		        }
			},{
				xtype:'panel',
				border:false,
				items:[{
					xtype:'button',
					text:'查询',
					handler:function(){
						var js=[],gc=[];
						var role = this.up('form').items.items[1].items.items;
						var stoage = this.up('form').items.items[2].items.items;
						for ( var i = 0; i < role.length; i++) {
							if(role[i].checked){
//								js += role[i].inputValue+",";
								js.push(role[i].inputValue);
							}
						}
						for ( var i = 0; i < stoage.length; i++) {
							if(stoage[i].checked){
								//gc += stoage[i].inputValue+",";
								gc.push(stoage[i].inputValue);
							}
						}
						console.log(d);
						Ext.Ajax.request({
							url:'vm/getTMVs.do',
							params:{
								roles:js,
								gcs:gc,
								taskId:d.id,
								taskType:me.type == 1?1:2,
								bzid:d.bz_id
							},
							success:function(response){
								//panel.remove(Ext.ComponentQuery.query('[xtype=videosplayer]',me));
								var items = panel.items.items;
								for ( var i = items.length -1; i >= 0 ; i--) {
									var item = items[i];
									if(item.xtype == 'videosplayer'){
										panel.remove(item);
									}
								}
								var text = Ext.decode(response.responseText);
								for ( var i = 0; i < text.length; i++) {
									var roleName = text[i].role == null?"":text[i].role;
									var gcName = text[i].gc == null?"":text[i].gc;
									panel.add({
										xtype: 'videosplayer',
										vdata: text[i].videos,
										title: roleName+'['+gcName+']',
										autoPlay: false,
										border: true,
										padding: '15 2 15 2',
										columnWidth: 1/3,
										height: 400
									});
								}
								
								/*
								var text = Ext.decode(response.responseText);
								var items = panel.items.items;
								for ( var i = items.length -1; i >= 0 ; i--) {
									var item = items[i];
									if(item.xtype == 'player'){
										panel.remove(item);
									}
								}
								for ( var i = 0; i < text.length; i++) {
									panel.add({
										xtype: 'player',
										vdata: text[i],
										title: text[i].jsname+'['+text[i].gcname+']',
										autoPlay: false,
										src: text[i].synpath,
										border: true,
										padding: '15 2 15 2',
										columnWidth: 1/3,
										height: 400
									});
								}
							*/}
						});
						
						
						/*var params = {};
						//得到所有的checkbox
						var checkboxs = Ext.ComponentQuery.query('form checkbox');
						for ( var i = 0; i < checkboxs.length; i++) {
							var temp = checkboxs[i];
							if(temp.checked){}
						}*/
					}
				},{
					xtype:'button',
					text:'全部（播放/暂停）',
					handler:function(){
						var flag = false;
						var items = me.query('videosplayer');
						if(items == null || items.length < 1){
							return;
						}
						Ext.Array.each(items,function(item){
							try {
								if(item.isPlay()){
									flag = true;
									return;
								}
							} catch (e) {}
						});
						Ext.Array.each(items,function(item){
							try {
								flag?item.pause():item.play();
							} catch (e) {}
						});
					}
				}]
			},{
				layout: 'column',
				xtype:'panel',
				id:me.id+'-tv',
				autoScroll:true,
				hidden: true,
				border:false,
				height: 500,
				bodyPadding:'15 0 0 0',
				defaults:{columnWidth:1/3,padding: '1 1 0 1',height:220},
		        items: []
			}],
			listeners: {/*
				afterrender: function(p){
					Ext.Ajax.request({
						url:'vm/getTMVs.do',
						params: {taskId:d.id},
						success:function(response){
							var text = Ext.decode(response.responseText);
							var _items = Ext.getCmp(me.id+'-tv');
							for ( var i = 0; i < text.length; i++) {
								panel.add({
									xtype: 'player',
									vdata: text[i],
									autoPlay: false,
									autoLoadVideo:false,
									title: text[i].jsname+'['+text[i].gcname+']',
									src: text[i].synpath,
									border: true,
									padding: '15 2 15 2',
									columnWidth: 1/3,
									height: 400
								});
							}
						}
					});
				}
			*/}
			
		});
		
		me.items = panel;
		me.callParent();
	},
});